#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using IPSim.Data;
using IPSim.Util;

namespace IPSim.Data
{
    /// <summary>
    /// Klasa koja predstavlja IP Adresu.
    /// </summary>
    public class IPAddress
    {
        private UInt32 m_ipAddress;
        public const UInt32 ipBroadcast = UInt32.MaxValue;

        public override bool Equals(System.Object obj)
        {
            // If parameter cannot be cast to IPAddress return false:
            IPAddress ipAddr = obj as IPAddress;
            if ((object)ipAddr == null)
            {
                return false;
            }

            // Return true if the addresses match
            return m_ipAddress == ipAddr.Address;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public IPAddress(uint ipAddress)
        {
            m_ipAddress = ipAddress;
        }


        public bool Equals(IPAddress ipAddress)
        {
            // Return true if the addresses match:
            return m_ipAddress == ipAddress.Address;
        }

        public UInt32 Address
        {
            get 
            {
                return m_ipAddress;
            }
        }

        public override string ToString()
        {
            return String.Format("{0:0}.{1:0}.{2:0}.{3:0}", ((m_ipAddress >> 24) & 0xff), ((m_ipAddress >> 16) & 0xff), ((m_ipAddress >> 8) & 0xff), ((m_ipAddress) & 0xff));
        }

        public readonly static IPAddress BroadcastAddress = new IPAddress(ipBroadcast);
    }
}
